<script>
	(function (window) {
    // 将小数点清零
    var toInteger = function (value) {
    value = Math.round(parseFloat(value));
    return value;
    };
    // 保留一位小数点
    var toDecimal = function (value) {
    value = Math.round(parseFloat(value) * 10) / 10;
    if (value.toString().indexOf(".") < 0) {
    value = value.toString() + ".0";
    }
    return value;
    }
    // 保留两位小数点
    var toFloat = function (value) {
    value = Math.round(parseFloat(value) * 100) / 100;
    if (value.toString().indexOf(".") < 0) {
    value = value.toString() + ".00";
    }
    return value;
    }
    // 保留两位小数点，一位小数自动补零
    var toZero = function (value) {
    value = Math.round(parseFloat(value) * 100) / 100;
    var xsd = value.toString().split(".");
    //Ext.log(xsd.length);
    if (xsd.length == 1) {
    value = value.toString() + ".00";
    return value;
    }
    if (xsd.length > 1) {
    if (xsd[1].length < 2) {
    value = value.toString() + "0";
    }
    return value;
    }
    }
    window.fomatFloat = {
    toInteger: toInteger,
    toDecimal: toDecimal,
    toFloat: toFloat,
    toZero: toZero,
    };
})(window);
</script>
<div class="container-fluid">
	<div class="line-1">
		<div class="form-group col-sm-6">
			<div class="row">
				<div class="col-sm-4">
					<input class="form-control" id="projectname_1581740645563_3150" placeholder="合并后项目名称">
				</div>
				<div class="col-sm-8">
					<button onclick="mergeProject()"  type="button" clickadd="true" class="btn btn-primary">合并项目</button>&nbsp;
				</div>
			</div>
		</div>
	</div>

	<div class="line-2">
		<div class="form-group col-sm-2">
			<select class="form-control" id="unit">
				<option value="">选择单位</option>
			</select>
		</div>
		<div class="form-group col-sm-2">
			<input class="form-control" id="projectname" placeholder="项目名称">
		</div>
		<div class="form-group col-sm-2">
			<select class="form-control" id="type">
				<option value="" >项目分类</option>
				<option value="货物类">货物类</option>
				<option value="服务类">服务类</option>
				<option value="工程类">工程类</option>
				<option value="电子卖场">电子卖场</option>
			</select>
		</div>
		<div class="form-group col-sm-2">
			<select class="form-control" id="origin">
				<option value="" >选择产地</option>
				<option value="国产">国产</option>
				<option value="进口">进口</option>
			</select>
		</div>
	</div>

	<div class="line-3">
		<div class="form-group col-sm-2">
			<select class="form-control" id="natureOfFunds">
				<option value="">资金性质</option>
				<option value="一般公共预算资金">一般公共预算资金</option>
				<option value="政府性基金资金">政府性基金资金</option>
				<option value="中央转移资金">中央转移资金</option>
				<option value="自筹资金">自筹资金</option>
				<option value="追加资金">追加资金</option>
				<option value="上年结转资金">上年结转资金</option>
			</select>
		</div>
		<div class="form-group col-sm-2">
			<select class="form-control" id="projectadminer">
				<option value="">项目负责人</option>
			</select>
		</div>
		<div class="form-group col-sm-2">
			<select class="form-control" id="detailSubject">
				<option value="" disabled>明细科目</option>
			</select>
		</div>
	</div>

	<div class="line-4">
		<div class="form-group col-sm-2">
			<select id="bugtype" class="form-control" >
				<option value="">采购方式</option>
				<option value="单一来源">单一来源</option>
				<option value="公开招标">公开招标</option>
				<option value="竞争性谈判">竞争性谈判</option>
				<option value="竞争性磋商">竞争性磋商</option>
				<option value="询价">询价</option>
				<option value="直采">直采</option>
				<option value="无过程采购">无过程采购</option>
			</select>
		</div>
		<div class="form-group col-sm-2">
			<select id="company" class="form-control" >
				<option value="">代理单位</option>
			</select>
		</div>
		<div class="form-group col-sm-2">
				<input class="form-control" id="projectNameFunds" placeholder="预算资金项目名称">
		</div>
		<div class="form-group col-sm-4">
			组织形式
			<select id="catalogue1_1-1" onchange="showFromLevel(2, '1-1')" class="form-control" style="width: 36%;display: inline-block;">
				<option value="" disabled>组织形式</option>
			</select>
			<select id="catalogue2_1-1" onchange="showFromLevel(3, '1-1')" class="form-control" style="width: 36%;display: inline-block;">
			</select>
		</div>
		<div class="form-group col-sm-4">
			预算金额
			<input value="" class="form-control" id="stbudget" style="width: 36%;display: inline;">
			到
			<input value="" class="form-control" id="enbudget" style="width: 36%;display: inline;">
		</div>

		<div class="form-group col-sm-2">
			<button onclick="search()" type="button" class="btn btn-primary col-sm-6">搜索</button>
			<button onclick="download()" type="button" class="btn btn-warning col-sm-6">下载</button>
		</div>
	</div>

</div>
<div id="nbxmsp_data" style="margin-top: 20px;">
	<tabs style="display:block;margin:1em auto;">
	<ul class="r-tabs" style="margin: 0;">
		<li class="r-tabs-item active">货物类</li>
		<li class="r-tabs-item">服务类</li>
		<li class="r-tabs-item">工程类</li>
		<li class="r-tabs-item">电子卖场</li>
	</ul>
	
	<div class="r-tabs-div" id="goodsConid">数据加载中...</div>
	<div class="r-tabs-div" id="serviceConid" style="display:none;">数据加载中...</div>
	<div class="r-tabs-div" id="supplyConid" style="display:none;">数据加载中...</div>
	<div class="r-tabs-div" id="pactConid" style="display:none;">数据加载中...</div>
	</tabs>
</div>
<script>
function tabAB(A,B){
	var $A=$(A),$B=$(B);
	$A.click(function(){
		var i=$A.index($(this));
		$A.removeClass('active').eq(i).addClass('active');
		$B.hide().eq(i).show();
		$("input[name='id_checked']").attr('checked',false);
	})
	};

tabAB('.r-tabs-item','.r-tabs-div');
function oninputblur(na, zb, obj){
	var nodeId = obj.parentNode.parentNode.id;
	var tmpArr = nodeId.split("_");
	if (tmpArr.length > 1) {
		var id = tmpArr[2];
		var v = obj.value;
		js.ajax(js.getajaxurl('updateApproveSubVal','index','cg'),
				{
				"id":id,"f":na,"v":v
				},function(s){
					var msg = s.msg;
					if(msg == "修改成功") {
					} else {
						alert(s.msg);
					}
				},'get,json',false,'');
	}
}

function mergeProject(){
	var ob_c = $("input[name='id_checked']");
	var s = "";
	for(var i=0;i<ob_c.length;i++){
		if(ob_c[i].checked && !ob_c[i].disabled){
			if (s == "") {
				s = ob_c[i].value;
			} else {
				s+=','+ob_c[i].value+'';
			}
			
		}
	}
	if (s == "") {
		alert("请选择要合并的项目");
		return ;
	}
	var projectname = $("#projectname_1581740645563_3150").val();
	if(projectname == "") {
		alert("合并项目名称不能为空");
		return ;
	}
	js.ajax(js.getajaxurl('mergeZbcgNewinfo','index','cg'),{
			ids:s, projectname:projectname, sericnum:'{base_sericnum}'
		},function(s){
		alert(s.msg);
		showSubData();
		//刷新界面
	},'get,json',false,'');
}
function delMergePro(id){
	js.ajax(js.getajaxurl('delMergeProject','index','cg'),{ 
			id:id,sericnum:'{base_sericnum}'
		},function(s){
			alert(s.msg);
			showSubData();
		//刷新界面
	},'get,json',false,'');
}
function showSubData(params = new Object()){

	params.mid = mid;
	js.ajax(js.getajaxurl('getXmnbspList','index','cg'),
		params,function(s){
			var content = "";
			
			content += "<table class='createrows x-scroll table-bordered' border='0' cellspacing='0' cellpadding='0' align='center'>";
			content += "<thead><tr>" +
							"<th style='min-width: 4em;'>勾选</th>" +
							"<th style='min-width: 4em;'>编号</th>" +
							"<th>单位名称</th>" +
							"<th>申请采购项目名称</th>" +
							"<th>项目分类</th>" +
							"<th>项目类别</th>" +
							"<th style='min-width: 4em;'>产地</th>" +
							"<th>预算总价</th>" +
							"<th>资金性质</th>" +
							"<th>预算资金项目名称</th>" +
							"<th>明细科目</th>" +
							"<th>组织形式</th>" +
							"<th>采购方式</th>" +
							"<th>代理单位</th>" +
							"<th>项目负责人</th>" +
							"<th>备注</th>" +
							"<th>附件</th>" +
							"<th>操作</th>" +
						"</tr></thead>";
	
		//货物类表格
		var goodsTableContent = content;
		var goodsIndex = 0;
		var goodsCompany = "";
		var goodsTotal = 0.00;
		var goodsMerProids = "";
		var goodsNum = 1;
		//服务类表格
		var serviceTableContent = content;
		var serviceIndex = 0;
		var serviceCompany = "";
		var serviceTotal = 0.00;
		var serviceMerProids = "";
		var serviceNum = 1;
		//工程类表格
		var projectTableContent = content;
		var projectIndex = 0;
		var projectCompany = "";
		var projectTotal = 0.00;
		var projectMerProids = "";
		var projectNum = 1;
		//电子卖场
		var pactTableContent = content;
		var pactIndex = 0;
		var pactCompany = "";
		var pactTotal = 0.00;
		var pactMerProids = "";
		var pactNum = 1;

		var lastGood = 0;
		var lastService = 0;
		var lastProject = 0;
		var lastPact = 0;
		for(w=0; w < s.length; w++){
			switch (s[w].type) {
				case '货物类':
					lastGood = w;
					break;
				case '服务类':
					lastService = w;
					break;
				case '工程类':
					lastProject = w;
					break;
				case '电子卖场':
					lastPact = w;
					break;
			}
		}

		$.each(s, function(i, field){
			var mergepeojectids = field.mergepeojectids;

			if (field.type == "货物类") {
				goodsTotal += parseFloat(field.budget);
				

				goodsIndex++;
				var iscanHebing = false;

				var nameRowsTmp = "";
				var catalogueRowsTmp = "";
				var buymodeRowsTmp = "";
				var proxycompanyRowsTmp = "";
				var projectadminerRowsTmp = "";

				var hebingNum = 0;
				var operaStr = "<td style='min-width:10em;word-wrap:break-word;word-break:break-all; '></td>";
				if (mergepeojectids != ""){
					operaStr = "<td onclick='delMergePro("+field.id+")'>取消合并</td>";
				}
				if(goodsMerProids != mergepeojectids && mergepeojectids != "") {
					goodsMerProids = mergepeojectids;
					hebingNum = mergepeojectids.split(",").length;
					//rowsTmp = " rowspan=\""+hebingNum+"\"";
					nameRowsTmp = "<td rowspan=\""+hebingNum+"\">"+field.name+"</td>";
					catalogueRowsTmp = "<td id=\"catalogue_input_"+field.id+"\" rowspan=\""+hebingNum+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.projectadminer_input+"</td>";
				} else if(mergepeojectids == ""){
					nameRowsTmp = "<td>"+field.name+"</td>";
					catalogueRowsTmp =  "<td id=\"catalogue_input_"+field.id+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\">"+field.projectadminer_input+"</td>";
				}
				if(goodsCompany == field.companyname) {
					goodsNum += 1;
				}
				if(goodsCompany != field.companyname && goodsNum >1) {
					goodsTotal = eval(goodsTotal-parseFloat(field.budget));
                    goodsTotal = fomatFloat.toZero(goodsTotal);

					goodsTableContent += "<tr>";
					goodsTableContent += "<td style='min-width: 4em;'></td>";
					goodsTableContent += "<td style='min-width: 4em;'>小计</td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td style='min-width: 4em;'></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td>"+goodsTotal+"</td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "</tr>";
				}
				if(goodsCompany != field.companyname) {
					goodsCompany = field.companyname;
					goodsTotal = eval(parseFloat(field.budget)-0);
					goodsNum = 1;
				}
				// if(field.dept != '') field.companyname = field.companyname+'-'+field.dept;
				goodsTableContent += "<tr>";
				goodsTableContent += "<td style='min-width: 4em;'><input type='checkbox' name='id_checked' value='"+field.id+"'></td>";
				goodsTableContent += "<td style='min-width: 4em;'>"+goodsIndex+"</td>";
				goodsTableContent += "<td>"+field.companyname+"</td>";
				goodsTableContent += nameRowsTmp;
				goodsTableContent += "<td>"+field.type+"</td>";
				goodsTableContent += "<td>"+field.item_category+"</td>";
				goodsTableContent += "<td style='min-width: 4em;'>"+field.producing_area+"</td>";
				goodsTableContent += "<td>"+field.budget+"</td>";
				goodsTableContent += "<td>"+field.funds_type+"</td>";
				goodsTableContent += "<td>"+field.budget_item_name+"</td>";
				goodsTableContent += "<td>"+field.detail+"</td>";

				goodsTableContent += catalogueRowsTmp;
				goodsTableContent += buymodeRowsTmp;
				goodsTableContent += proxycompanyRowsTmp;
				goodsTableContent += projectadminerRowsTmp;
				goodsTableContent += "<td id=\"note_input_"+field.id+"\">"+field.note_input+"</td>";
				goodsTableContent  += "<td id=\"upfile_input"+field.id+"\" style='min-width:10em;word-wrap:break-word;word-break:break-all; '>"+field.upfile_input+"</td>";
				goodsTableContent += operaStr;
				goodsTableContent += "</tr>";
				if(i == lastGood && goodsNum > 1) {
					goodsTableContent += "<tr>";
					goodsTableContent += "<td style='min-width: 4em;'></td>";
					goodsTableContent += "<td style='min-width: 4em;'>小计</td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td style='min-width: 4em;'></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td>"+goodsTotal+"</td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td></td>";
					goodsTableContent += "<td ></td>";
					goodsTableContent += "<td ></td>";
					goodsTableContent += "<td ></td>";
					goodsTableContent += "<td ></td>";
					goodsTableContent += "<td ></td>";
					goodsTableContent += "<td ></td>";
					goodsTableContent += "</tr>";
				}

			} else if (field.type == "服务类"){
				serviceTotal += parseFloat(field.budget);
				serviceIndex++;
				var iscanHebing = false;
				var nameRowsTmp = "";
				var catalogueRowsTmp = "";
				var buymodeRowsTmp = "";
				var proxycompanyRowsTmp = "";
				var projectadminerRowsTmp = "";

				var hebingNum = 0;
				var operaStr = "<td style='min-width:10em;word-wrap:break-word;word-break:break-all; '></td>";
				if (mergepeojectids != ""){
					operaStr = "<td onclick='delMergePro("+field.id+")'>取消合并</td>";
				}
				if(serviceMerProids != mergepeojectids && mergepeojectids != "") {
					serviceMerProids = mergepeojectids;
					hebingNum = mergepeojectids.split(",").length;
					nameRowsTmp = "<td rowspan=\""+hebingNum+"\">"+field.name+"</td>";
					catalogueRowsTmp = "<td id=\"catalogue_input_"+field.id+"\" rowspan=\""+hebingNum+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.projectadminer_input+"</td>";
				} else if(mergepeojectids == ""){
					nameRowsTmp = "<td>"+field.name+"</td>";
					catalogueRowsTmp =  "<td id=\"catalogue_input_"+field.id+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\">"+field.projectadminer_input+"</td>";
				}
				if(serviceCompany == field.companyname) {
					serviceNum += 1;
				}
				if(serviceNum >1 && serviceCompany != field.companyname) {
					//serviceTotal = serviceTotal - eval(parseFloat(field.budget)-0);
					serviceTotal = eval(serviceTotal-parseFloat(field.budget));
                    serviceTotal = fomatFloat.toZero(serviceTotal);

					serviceTableContent += "<tr>";
					serviceTableContent += "<td style='min-width: 4em;'></td>";
					serviceTableContent += "<td style='min-width: 4em;'>小计</td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td style='min-width: 4em;'></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td>"+serviceTotal+"</td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "</tr>";
				}
				if(serviceCompany != field.companyname) {
					serviceCompany = field.companyname;
					serviceTotal = eval(parseFloat(field.budget)-0);
					serviceNum = 1;
				}

				// if(field.dept != '') field.companyname = field.companyname+'-'+field.dept;
				serviceTableContent += "<tr>";
				serviceTableContent += "<td style='min-width: 4em;'><input type='checkbox' name='id_checked' value='"+field.id+"'></td>";
				serviceTableContent += "<td style='min-width: 4em;'>"+serviceIndex+"</td>";
				serviceTableContent += "<td>"+field.companyname+"</td>";
				serviceTableContent += nameRowsTmp;
				serviceTableContent += "<td>"+field.type+"</td>";
				serviceTableContent += "<td>"+field.item_category+"</td>";
				serviceTableContent += "<td style='min-width: 4em;'>"+field.producing_area+"</td>";
				serviceTableContent += "<td>"+field.budget+"</td>";
				serviceTableContent += "<td>"+field.funds_type+"</td>";
				serviceTableContent += "<td>"+field.budget_item_name+"</td>";
				serviceTableContent += "<td>"+field.detail+"</td>";
				serviceTableContent += catalogueRowsTmp;
				serviceTableContent += buymodeRowsTmp;
				serviceTableContent += proxycompanyRowsTmp;
				serviceTableContent += projectadminerRowsTmp;
				serviceTableContent += "<td id=\"note_input_"+field.id+"\">"+field.note_input+"</td>";
				serviceTableContent  += "<td id=\"upfile_input"+field.id+"\" style='min-width:10em;word-wrap:break-word;word-break:break-all; '>"+field.upfile_input+"</td>";
				serviceTableContent += operaStr;
				serviceTableContent += "</tr>";
				if(i == lastService && serviceNum > 1) {
					serviceTableContent += "<tr>";
					serviceTableContent += "<td style='min-width: 4em;'></td>";
					serviceTableContent += "<td style='min-width: 4em;'>小计</td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td style='min-width: 4em;'></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td>"+serviceTotal+"</td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "<td ></td>";
					serviceTableContent += "</tr>";
				}

			} else if (field.type == "工程类"){
				//projectTotal += eval(parseFloat(field.budget)-0);
                projectTotal += parseFloat(field.budget);
				projectIndex++;
				var iscanHebing = false;
				var nameRowsTmp = "";
				var catalogueRowsTmp = "";
				var buymodeRowsTmp = "";
				var proxycompanyRowsTmp = "";
				var projectadminerRowsTmp = "";

				var hebingNum = 0;
				if(projectMerProids != mergepeojectids && mergepeojectids != "") {
					projectMerProids = mergepeojectids;
					hebingNum = mergepeojectids.split(",").length;
					//rowsTmp = " rowspan=\""+hebingNum+"\"";
					nameRowsTmp = "<td rowspan=\""+hebingNum+"\">"+field.name+"</td>";
					catalogueRowsTmp = "<td id=\"catalogue_input_"+field.id+"\" rowspan=\""+hebingNum+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.projectadminer_input+"</td>";
				} else if(mergepeojectids == ""){
					nameRowsTmp = "<td>"+field.name+"</td>";
					catalogueRowsTmp =  "<td id=\"catalogue_input_"+field.id+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\">"+field.projectadminer_input+"</td>";
				}
				var operaStr = "<td style='min-width:10em;word-wrap:break-word;word-break:break-all; '></td>";
				if (mergepeojectids != ""){
					operaStr = "<td onclick='delMergePro("+field.id+")'>取消合并</td>";
				}

				if(projectCompany == field.companyname) {
					projectNum += 1;
				}
				if(projectNum >1 && projectCompany != field.companyname) {
					//projectTotal = projectTotal - eval(parseFloat(field.budget)-0);
					projectTotal = eval(projectTotal-parseFloat(field.budget));
                    projectTotal = fomatFloat.toZero(projectTotal);
					projectTableContent += "<tr>";
					projectTableContent += "<td style='min-width: 4em;'></td>";
					projectTableContent += "<td style='min-width: 4em;'>小计</td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td style='min-width: 4em;'></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td>"+projectTotal+"</td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "</tr>";

				}
				if(projectCompany != field.companyname) {
					projectCompany = field.companyname;
					projectTotal = eval(parseFloat(field.budget)-0);
					projectNum = 1;
				}

				// if(field.dept != '') field.companyname = field.companyname+'-'+field.dept;
                projectTableContent += "<tr>";
                projectTableContent += "<td style='min-width: 4em;'><input type='checkbox' name='id_checked' value='"+field.id+"'></td>";
                projectTableContent += "<td style='min-width: 4em;'>"+projectIndex+"</td>";
                projectTableContent += "<td>"+field.companyname+"</td>";
                projectTableContent += nameRowsTmp;
                projectTableContent += "<td>"+field.type+"</td>";
				projectTableContent += "<td>"+field.item_category+"</td>";
                projectTableContent += "<td style='min-width: 4em;'>"+field.producing_area+"</td>";
                projectTableContent += "<td>"+field.budget+"</td>";
                projectTableContent += "<td>"+field.funds_type+"</td>";
                projectTableContent += "<td>"+field.budget_item_name+"</td>";
                projectTableContent += "<td>"+field.detail+"</td>";
				projectTableContent += catalogueRowsTmp;
				projectTableContent += buymodeRowsTmp;
				projectTableContent += proxycompanyRowsTmp;
				projectTableContent += projectadminerRowsTmp;
                projectTableContent += "<td id=\"note_input_"+field.id+"\">"+field.note_input+"</td>";
				projectTableContent += "<td id=\"upfile_input"+field.id+"\" style='min-width:10em;word-wrap:break-word;word-break:break-all; '>"+field.upfile_input+"</td>";
                projectTableContent += operaStr;
				projectTableContent += "</tr>";
				if(i == lastProject && projectNum > 1) {
					projectTableContent += "<tr>";
					projectTableContent += "<td style='min-width: 4em;'></td>";
					projectTableContent += "<td style='min-width: 4em;'>小计</td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td style='min-width: 4em;'></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td>"+projectTotal+"</td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "<td ></td>";
					projectTableContent += "</tr>";
				}

			}else if (field.type == "电子卖场"){
				//pactTotal += eval(parseFloat(field.budget)-0);
				pactTotal += parseFloat(field.budget);
				pactIndex++;
				var iscanHebing = false;
				var nameRowsTmp = "";
				var catalogueRowsTmp = "";
				var buymodeRowsTmp = "";
				var proxycompanyRowsTmp = "";
				var projectadminerRowsTmp = "";

				var hebingNum = 0;
				if(pactMerProids != mergepeojectids && mergepeojectids != "") {
					pactMerProids = mergepeojectids;
					hebingNum = mergepeojectids.split(",").length;
					//rowsTmp = " rowspan=\""+hebingNum+"\"";
					nameRowsTmp = "<td rowspan=\""+hebingNum+"\">"+field.name+"</td>";
					catalogueRowsTmp = "<td id=\"catalogue_input_"+field.id+"\" rowspan=\""+hebingNum+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\" rowspan=\""+hebingNum+"\">"+field.projectadminer_input+"</td>";
				} else if(mergepeojectids == ""){
					nameRowsTmp = "<td>"+field.name+"</td>";
					catalogueRowsTmp =  "<td id=\"catalogue_input_"+field.id+"\"><select id='catalogue1_"+field.id+"' onchange=\"showFromLevel(2,"+field.id+")\"></select><select id='catalogue2_"+field.id+"' onchange=\"showFromLevel(3,"+field.id+")\"></select></td>";
					buymodeRowsTmp = "<td id=\"buymode_input_"+field.id+"\">"+field.buymode_input+"</td>";
					proxycompanyRowsTmp = "<td id=\"proxycompany_input_"+field.id+"\">"+field.proxycompany_input+"</td>";
					projectadminerRowsTmp = "<td id=\"projectadminer_input_"+field.id+"\">"+field.projectadminer_input+"</td>";
				}
				var operaStr = "<td style='min-width:10em;word-wrap:break-word;word-break:break-all; '></td>";
				if (mergepeojectids != ""){
					operaStr = "<td onclick='delMergePro("+field.id+")'>取消合并</td>";
				}

				if(pactCompany == field.companyname) {
					pactNum += 1;
				}
				if(pactCompany != field.companyname && pactNum >1) {
					//pactTotal = pactTotal - eval(parseFloat(field.budget)-0);
					pactTotal = eval(pactTotal-parseFloat(field.budget));
                    pactTotal = fomatFloat.toZero(pactTotal);
					pactTableContent += "<tr>";
					pactTableContent += "<td style='min-width: 4em;'></td>";
					pactTableContent += "<td style='min-width: 4em;'>小计</td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td style='min-width: 4em;'></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td>"+pactTotal+"</td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "</tr>";
				}
				if(pactCompany != field.companyname) {
					pactCompany = field.companyname;
					pactTotal = parseInt(field.budget);
					pactNum = 1;
				}

				// if(field.dept != '') field.companyname = field.companyname+'-'+field.dept;
				pactTableContent += "<tr>";
				pactTableContent += "<td style='min-width: 4em;'><input type='checkbox' name='id_checked' value='"+field.id+"'></td>";
				pactTableContent += "<td style='min-width: 4em;'>"+pactIndex+"</td>";
				pactTableContent += "<td>"+field.companyname+"</td>";
				pactTableContent += nameRowsTmp;
				pactTableContent += "<td>"+field.type+"</td>";
				pactTableContent += "<td>"+field.item_category+"</td>";
				pactTableContent += "<td style='min-width: 4em;'>"+field.producing_area+"</td>";
				pactTableContent += "<td>"+field.budget+"</td>";
				pactTableContent += "<td>"+field.funds_type+"</td>";
				pactTableContent += "<td>"+field.budget_item_name+"</td>";
				pactTableContent += "<td>"+field.detail+"</td>";

				pactTableContent += catalogueRowsTmp;
				pactTableContent += buymodeRowsTmp;
				pactTableContent += proxycompanyRowsTmp;
				pactTableContent += projectadminerRowsTmp;
				pactTableContent += "<td id=\"note_input_"+field.id+"\">"+field.note_input+"</td>";
				pactTableContent  += "<td id=\"upfile_input"+field.id+"\" style='min-width:10em;word-wrap:break-word;word-break:break-all; '>"+field.upfile_input+"</td>";
				pactTableContent += operaStr;
				pactTableContent += "</tr>";
				if(i == lastPact && pactNum >1) {
					pactTableContent += "<tr>";
					pactTableContent += "<td style='min-width: 4em;'></td>";
					pactTableContent += "<td style='min-width: 4em;'>小计</td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td style='min-width: 4em;'></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td>"+pactTotal+"</td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "<td ></td>";
					pactTableContent += "</tr>";
				}
			}
		});
		
		var endContent = "</table>";
		goodsTableContent += endContent;
		serviceTableContent += endContent;
		projectTableContent += endContent;
		pactTableContent += endContent;
		$("#goodsConid").html(goodsTableContent);
		$("#serviceConid").html(serviceTableContent);
		$("#supplyConid").html(projectTableContent);
		$("#pactConid").html(pactTableContent);

		$.each(s, function(i, field){
			showFromLevel(1, field.id, field.catalogue);
		});
	},'get,json',false,'');
}
$(document).ready(function(){
	showSubData();
});
function showFromLevel(level, id, val=null) {
	if(val != null) {
		catalogueNames = val.split('-');
		for(i=0; i<catalogueNames.length; i++){
			var content = "";
			var catalogueid = "";
			// console.log(catalogueNames[i]+id);
			var num = i + 1;
			if (num == 1) {
				content += getOptionStr("分散采购,部门采购,政府采购", catalogueNames[0]);
				catalogueid = "catalogue1_"+id+"";
			} else if(num == 2) {
				catalogueid = "catalogue2_"+id+"";
				if (catalogueNames[0] == "部门采购") {
					content += getOptionStr("自行组织,委托采购", catalogueNames[1]);
				} else if (catalogueNames[0] == "分散采购") {
					content += getOptionStr("自行组织,委托采购", catalogueNames[1]);
				} else {
					content += getOptionStr("");
				}
			}
			$("#"+catalogueid).html("");
			$("#"+catalogueid).append(content);
			// $("#"+catalogueid).val(val);
		}
	}else{
		var content = "";
		var catalogueid = "";
		if (level == 1) {
			content += getOptionStr("分散采购,部门采购,政府采购");
			catalogueid = "catalogue1_"+id+"";
		} else if(level == 2) {
			catalogueid = "catalogue2_" + id + "";
			var level1Val = $("#catalogue1_" + id).val();
			if (level1Val == "部门采购") {
				content += getOptionStr("自行组织,委托采购");
			} else if (level1Val == "分散采购") {
				content += getOptionStr("自行组织,委托采购");
			}else {
				content += getOptionStr("");
			}
		}
		$("#"+catalogueid).html("");
		$("#"+catalogueid).append(content);
		$("#"+catalogueid).val(val);
		var v1 = $("#catalogue1_"+id).val();
		if(v1 == "政府采购" && id != '1-1') {
			this.saveCatalogue(id);
		}
		var v2 = $("#catalogue2_"+id).val();
		if(v2 == "自行组织" || v2 == "委托采购") {
			if( id != '1-1') {
				this.saveCatalogue(id);
			}
		}
	}
}
function saveCatalogue(id){
	var v1 = $("#catalogue1_"+id).val();
	var v2 = $("#catalogue2_"+id).val();
	var v = v1;
	if(v2 != "") {
		v += "-"+v2;
	} else if (v1 == '政府采购'){
		v = v1;
	} else {
		return;
	}
	js.ajax(js.getajaxurl('updateApproveSubVal','index','cg'),
			{
			"id":id,"f":"catalogue","v":v
			},function(s){
				var msg = s.msg;
				if(msg == "修改成功") {
				} else {
					alert(s.msg);
				}
			},'get,json',false,'');
}
function getOptionStr(str, name = null){
	var arr = str.split(",");
	var sss = "<option value=''>请选择</option>";
	for(var i=0;i<arr.length;i++){
		if(name == arr[i]){
			sss += "<option value='"+arr[i]+"' selected=\"selected\">"+arr[i]+"</option>";
		}else{
			sss += "<option value='"+arr[i]+"'>"+arr[i]+"</option>";
		}
	}
	return sss;
}

$(document).ready(function(){
	function loadProjectadminer(){
		$.ajax({ url: "./index.php?a=loadProjectadminner&m=index&d=cg&ajaxbool=true", success: function(obj){
				var ccc ="<option value=''>项目负责人</option>";
				obj = JSON.parse(obj);
				data = obj;
				for(i=0;i<data.length;i++){
					ccc += "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
				};
				$('#projectadminer').html(ccc);
		}});

		$.ajax({ url: "./index.php?a=getDljgs&m=index&d=cg&ajaxbool=true", success: function(obj){
				var ccc ="<option value=''>代理机构</option>";
				obj = JSON.parse(obj);
				data = obj;
				for(i=0;i<data.length;i++){
					ccc += "<option value='"+data[i].name+"'>"+data[i].name+"</option>";
				};
				$('#company').html(ccc);
		}});

		$.ajax({ url: "./index.php?a=getCompanyList&m=main&d=report&ajaxbool=true", success: function(obj){
				var ccc ="<option value=''>选择单位</option>";
				obj = JSON.parse(obj);
				data = obj.rows;
				for(i=0;i<data.length;i++){
					ccc += "<option value='"+data[i].name+"'>"+data[i].name+"</option>";
				};
				$('#unit').html(ccc);
		}});

		$.ajax({ url: "./index.php?a=getDetailSubject&m=index&d=cg&ajaxbool=true", success: function(obj){
				var ccc ="<option value=''>明细科目</option>";
				obj = JSON.parse(obj);
				data = obj;
				for(i=0;i<obj.length;i++){
					ccc += "<option value='"+data[i]+"'>"+data[i]+"</option>";
				};
				$('#detailSubject').html(ccc);
		}});

		showFromLevel(1, '1-1');
	}
	loadProjectadminer();
});

//搜索
function search() {
	var unit = $('#unit').val();
	var projectname = $('#projectname').val();
	var types = $('#type').val();
	var origins = $('#origin').val();
	var stbudget = $('#stbudget').val();
	var enbudget = $('#enbudget').val();
	var natureOfFunds = $('#natureOfFunds').val();
	var projectadminer = $('#projectadminer').val();
	var detailSubject = $('#detailSubject').val();
	var catalogue1 = $('#catalogue1_1-1').val();
	var catalogue2 = $('#catalogue2_1-1').val();
	var bugtype = $('#bugtype').val();
	var company = $('#company').val();
	var projectNameFunds = $('#projectNameFunds').val();
	var catalogue = '';
	if (catalogue2 != "" && catalogue2 != null) {
		catalogue = catalogue1 + '-' + catalogue2;
	} else if (catalogue1 == '政府采购') {
		catalogue = catalogue1;
	}
	var params = {
		'unit':unit,
		'projectname':projectname,
		'types':types,
		'origins':origins,
		'stbudget':stbudget,
		'enbudget':enbudget,
		'natureOfFunds':natureOfFunds,
		'projectadminer':projectadminer,
		'detailSubject':detailSubject,
		'catalogue':catalogue,
		'bugtype':bugtype,
		'company':company,
		'projectNameFund':projectNameFunds,
	}
	showSubData(params);
}

//下载
function download()
{
	var unit = $('#unit').val();
	var projectname = $('#projectname').val();
	var types = $('#type').val();
	var origins = $('#origin').val();
	var stbudget = $('#stbudget').val();
	var enbudget = $('#enbudget').val();
	var natureOfFunds = $('#natureOfFunds').val();
	var projectadminer = $('#projectadminer').val();
	var detailSubject = $('#detailSubject').val();
	var catalogue1 = $('#catalogue1_1-1').val();
	var catalogue2 = $('#catalogue2_1-1').val();
	var bugtype = $('#bugtype').val();
	var company = $('#company').val();
	var projectNameFunds = $('#projectNameFunds').val();
	var catalogue = '';
	if (catalogue2 != "" && catalogue2 != null) {
		catalogue = catalogue1 + '-' + catalogue2;
	} else if (catalogue1 == '政府采购') {
		catalogue = catalogue1;
	}
	window.open('./index.php?a=nbxmsp&m=office|index&d=cg&ajaxbool=true&unit='+unit+'&projectname='+projectname+'&types='+types+'&origins='+origins+'&stbudget='+stbudget+'&enbudget='+enbudget+'&natureOfFunds='+natureOfFunds+'&projectadminer='+projectadminer+'&detailSubject='+detailSubject+'&catalogue='+catalogue+'&bugtype='+bugtype+'&company='+company+'&projectNameFund='+projectNameFunds+'&id='+mid);
}
</script>